import { ref, computed } from 'vue'
import { defineStore, storeToRefs } from 'pinia'
import { useTypeStore } from './type'

export const useCounterStore = defineStore('counter', () => {
  // 1 state
  const count = ref(0)
  // 2 get
  const doubleCount = computed(() => count.value * 2)
  const typeCount = computed(() => {
    // 在useCounterStore中访问useTypeStore的state
    const typeStore = useTypeStore()
    const { name } = storeToRefs(typeStore)
    return name.value + count.value
  })
  // 3 action
  const incrementAction = () => {
    count.value++
  }
  return { count, doubleCount, typeCount, incrementAction }
})
